import Vue from 'vue'
import App from './App'
import {
	baseRequest,
	tokenRequest
} from 'common/request.js'
// MD5 加密
import md5Libs from "uview-ui/libs/function/md5";
// UI
import uView from "uview-ui";
Vue.use(uView);

// #ifdef H5
import { wxPay } from './common/wxpay.config.js'
// #endif

// API
Vue.prototype.$baseRequest = baseRequest
Vue.prototype.$tkRequest = tokenRequest

// 检查登录
Vue.prototype.$isOnline = uni.getStorageSync('tk') ? true : false;

Vue.config.productionTip = false

// #ifdef H5
Vue.prototype.$wxPay = wxPay;
// #endif

App.mpType = 'app'

const app = new Vue({
	...App
})

import install from '@/common/http.interceptor.js'
Vue.use(install, app)

/* 获取微赞云接口token */
Vue.prototype.$getToken = function() {
	const account = 'Vzan1477935558', // 账号
	key = '45abbeeb9a9f484fa9bc1e8f5a19d98c', // 密钥
	timestamp = Math.round(new Date() / 1000); // 时间戳
	this.$u.post('/token/get_token', {
		account: account,
		signkey: md5Libs.md5(key + timestamp),
		timestamp: timestamp
	}).then(res => {
		let token = res.dataobj.token;
		uni.setStorageSync('token', token)
	})
}

app.$mount()
